package com.xiashitech.agent.proxy.hutool;

import com.xiashitech.agent.cache.classloader.ClassLoaderCache;
import com.xiashitech.agent.config.StartConfig;

import java.util.ArrayList;
import java.util.List;

public class StrUtil {

    private static String className = "cn.hutool.core.util.StrUtil";

    public static String format(CharSequence template, Object... params) {
        try {
            Class strUtilClass = ClassLoaderCache.getLaunchClassLoader().loadClass(className);
            return (String)strUtilClass.getMethod("format", CharSequence.class, Object[].class).invoke(null,template,params);
        } catch (Throwable e) {
            StartConfig.throwableStackPrinter(e);
        }
        return "null";//和hutool语义保持一致
    }

    public static List<String> split(CharSequence str, CharSequence separator) {
        try {
            Class strUtilClass = ClassLoaderCache.getLaunchClassLoader().loadClass(className);
            return (List<String>) strUtilClass.getMethod("split", CharSequence.class, CharSequence.class).invoke(null, str, separator);
        } catch (Throwable e) {
            StartConfig.throwableStackPrinter(e);
        }
        return new ArrayList<>();
    }
}






















